<template>
  <div>
    <!--搜索-->
    <div class="panel-container">
      <searchuinew :searchFormArr="searchFormArr" @searchParma="searchParma" :isAccording="isAccording" ref="searchuinew"></searchuinew>
    </div>
    <!--数据信息-->
    <div class="panel-container no-margin">
      <el-table :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
        <el-table-column align="center" header-align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" header-align="center" label="电话号" prop="phone" width="200"></el-table-column>
        <el-table-column align="center" header-align="center" label="短信模板id" prop="sms_id"></el-table-column>
        <el-table-column align="center" header-align="center" label="发送状态" prop="resp_sts_show"></el-table-column>
        <el-table-column align="center" header-align="center" label="短信类型" prop="sms_type_show" width="150"></el-table-column>
        <el-table-column align="center" header-align="center" label="发送时间" prop="created_time" width="150"></el-table-column>
      </el-table>
      <el-pagination
        small
        background
        :current-page="pageIndex"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100]"
        :total="totalPage"
        @current-change="currentChangeHandle"
        @size-change="sizeChangeHandle"
        layout="total, sizes, prev, pager, next, jumper"
        style="margin-top: 20px; text-align: right"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { apiMsgList } from '@/api/assetsDisposal'
export default {
  name: 'index',
  components: {},
  props: {
    id: {
      type: String,
      default: '',
    },
  },
  data() {
    const respStsList = [
      { id: 2, text: '成功' },
      { id: 3, text: '失败' },
    ]
    return {
      respStsList,
      searchFormArr: [
        // {
        //   fieldName: '计划id：',
        //   type: 'input',
        //   field: 'plan_id',
        //   placeholder: '请输入计划id',
        // },
        {
          fieldName: '执行状态：',
          type: 'select',
          field: 'sts',
          option: respStsList,
          placeholder: '请选择',
        },
      ],
      isAccording: true,
      searchParams: {
        plan_id: '',
        sts: '',
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
    }
  },
  mounted() {
    this.searchParams.plan_id = this.id
    // this.searchFormArr.find((item) => item.field === 'plan_id').default = this.id
    // this.$refs.searchuinew.resetForm()
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = Object.assign({ pageNumber: this.pageIndex, pageSize: this.pageSize }, this.searchParams)
      const formData = new FormData()
      for (let key in info) {
        formData.set(key, info[key])
      }
      apiMsgList(formData)
        .then((res) => {
          const { items, total } = res.result
          const smsTypeList = [
            { id: 1, name: 'crm运营' },
            { id: 2, name: '外呼回调' },
          ]
          items.forEach((item) => {
            const respItem = this.respStsList.find((resp) => {
              return resp.id === item.resp_sts
            })
            if (respItem) {
              item.resp_sts_show = respItem.text
            }
            const smsItem = smsTypeList.find((resp) => {
              return resp.id === item.sms_type
            })
            if (smsItem) {
              item.sms_type_show = smsItem.name
            }
          })
          this.dataList = items
          this.totalPage = total
          this.dataListLoading = false
        })
        .catch((e) => {
          this.dataList = []
          this.totalPage = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      console.log(e)
      this.searchFormArr.forEach((item) => {
        if (item.field === 'time') return
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      this.pageIndex = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
  },
}
</script>

<style scoped lang="scss"></style>
